<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    <title>ShellCheck: SC1007 – Remove space after `=` if trying to assign a value (or for empty string, use `var=''` ... ).</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
  </head>
  <body style="margin-left: auto; margin-right: auto; max-width: 800px">
    <h1>SC1007 – ShellCheck Wiki</h1>
    <a href="https://github.com/koalaman/shellcheck/wiki/SC1007">See this page on GitHub</a>
    <p style="display: none"><a href="index.html">Sitemap</a></p>
    <hr />
    <h1
id="remove-space-after--if-trying-to-assign-a-value-or-for-empty-string-use-var--">Remove
space after <code>=</code> if trying to assign a value (or for empty
string, use <code>var=''</code> ... ).</h1>
<h3 id="problematic-code">Problematic code:</h3>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="SC1007.html#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co"># I want programs to show text in Dutch!</span></span>
<span id="cb1-2"><a href="SC1007.html#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="va">LANGUAGE</span><span class="op">=</span> <span class="fu">nl</span></span></code></pre></div>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="SC1007.html#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co"># I want to run the nl command with English error messages!</span></span>
<span id="cb2-2"><a href="SC1007.html#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="va">LANGUAGE</span><span class="op">=</span> <span class="fu">nl</span></span></code></pre></div>
<h3 id="correct-code">Correct code:</h3>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="SC1007.html#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># I want programs to show text in Dutch!</span></span>
<span id="cb3-2"><a href="SC1007.html#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="va">LANGUAGE</span><span class="op">=</span>nl</span></code></pre></div>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="SC1007.html#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="co"># I want to run the nl command with English error messages!</span></span>
<span id="cb4-2"><a href="SC1007.html#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="va">LANGUAGE</span><span class="op">=</span><span class="st">&#39;&#39;</span> <span class="fu">nl</span></span></code></pre></div>
<h3 id="rationale">Rationale:</h3>
<p>It's easy to think that <code>LANGUAGE= nl</code> would assign
<code>"nl"</code> to the variable <code>LANGUAGE</code>. It doesn't.</p>
<p>Instead, it runs <code>nl</code> (the "number lines" command) and
sets <code>LANGUAGE</code> to an empty string in its environment.</p>
<p>Since trying to assign values this way is a common mistake,
ShellCheck warns about it and asks you to be explicit when assigning
empty strings (except for <code>IFS</code>, due to the common
<code>IFS= read ..</code> idiom).</p>
<h3 id="exceptions">Exceptions</h3>
<p>If you're familiar with this behavior and feel that the explicit
version is unnecessary, you can <a href="ignore.html">ignore</a> it.</p>
    <hr />
    <p style='font-size: 80%'><a href="../index.html">ShellCheck</a> is a static analysis tool for shell scripts. This page is part of its documentation.</p>
  </body>
</html>


